import 'package:flutter/material.dart';
import 'package:dio/dio.dart';

class HomePage extends StatefulWidget {
  @override
  _home_pageState createState() => _home_pageState();
}

class _home_pageState extends State<HomePage> {
  TextEditingController typeController = TextEditingController();
  String showText = "啥玩应啊2";

  Future getHttp(String TypeText) async {
    try {
      var data = {'name': TypeText};
      print(data);
      Response rs = await Dio().get(
          'https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&sugsid=1448,21084,30473,26350&wd=q&req=2&bs=easy-mock&pbs=easy-mock&csor=1&pwd=easy-mock&cb=jQuery110205767964097366007_1579100948470&_=1579100948493');
      return rs.data;
      // post请求
      // Response rs = await Dio().post(
      //     "https://www.easy-mock.com/mock/5e1f4762fe6d23409285a84a/fameex_app/getUserInfo",
      //     queryParameters: data,
      // );

    } catch (e) {}
  }

  void _onChange() {
    if (typeController.text.toString() == '') {
      showDialog(
          context: context,
          builder: (context) => AlertDialog(title: Text('美女类型不能为空')));
    } else {
      getHttp(typeController.text.toString()).then((val) {
        setState(() {
          showText = val;
        });
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Scaffold(
        appBar: AppBar(
          title: Text('美好人间'),
        ),
        body: Container(
          child: Column(
            children: <Widget>[
              TextField(
                controller: typeController,
                autofocus: false,
                decoration: InputDecoration(
                    contentPadding: EdgeInsets.all(10.0),
                    labelText: '美女类型',
                    helperText: '请输入你喜欢的类型'),
              ),
              RaisedButton(
                onPressed: () {
                  _onChange();
                },
                child: Text('选择完毕'),
              ),
              Container(
                child: Text(
                  showText,
                  // overflow: TextOverflow.ellipsis,
                  maxLines: 30,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
